package com.cmf.myproject.controller.boss.user;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cmf.myproject.dal.mybatis.model.User;
import com.cmf.myproject.service.user.dto.UserAddItemReqDto;
import com.cmf.myproject.service.user.dto.UserUpdateItemReqDto;
import com.cmf.myproject.service.user.UserService;
import com.cmf.myproject.service.user.dto.UserQueryFilter;
import com.system.core.controller.ControllerBase;
import com.system.core.results.ResultBase;
import com.system.core.view.layui.table.TableViewRspDto;

@Controller
@RequestMapping("boss/user")
public class UserController extends ControllerBase {
	@Autowired
	private UserService userService;
	
	@RequiresPermissions("user_topage")
	@RequestMapping(value = "to_page",method = RequestMethod.GET)
	public String toPage() {
		return "/boss/user/user-list";
	}
	
	@RequestMapping(value = "query_list",method = RequestMethod.POST)
	@ResponseBody
	public TableViewRspDto<User> userQueryList(UserQueryFilter filter) {
		TableViewRspDto<User> rsp = userService.userList(filter);
		return rsp;
	}
	
	@RequestMapping(value = "get_item_by_key",method = RequestMethod.POST)
	@ResponseBody
	public User userGetByPrimaryKey(User user){
		return userService.userGetByPrimaryKey(user);
	}
	
	@RequiresPermissions("user_add_opt")
	@RequestMapping(value = "add_item",method = RequestMethod.POST)
	@ResponseBody
	public ResultBase userAddItem(@Validated UserAddItemReqDto userAddItemReqDto) {
		return userService.userSave(userAddItemReqDto);
	}
	
	@RequiresPermissions("user_edit_opt")
	@RequestMapping(value = "update_item",method = RequestMethod.POST)
	@ResponseBody
	public ResultBase userUpdateItem(@Validated UserUpdateItemReqDto userUpdateItemReqDto) {
		return userService.userUpdateByPrimaryKey(userUpdateItemReqDto);
	}
	
	@RequiresPermissions("user_delete_opt")
	@RequestMapping(value = "delete_item",method = RequestMethod.POST)
	@ResponseBody
	public ResultBase userDeleteItem(@RequestBody List<Long> keys) {
		return userService.userDeleteByPrimaryKey(keys);
	}
}
